#!/usr/bin/env python
from fastapi import FastAPI
from langchain.prompts import ChatPromptTemplate
from utils import get_qwen_models
from langserve import add_routes

llm, _, _ = get_qwen_models() 

# 创建应用
app = FastAPI(
    title="LangChain Server",
    version="1.0",
    description="A simple api server using Langchain's Runnable interfaces",
)


# 注意template格式, 传参的变量名要与server中定义的一致，这里是topic
# 构建应用
prompt = ChatPromptTemplate.from_template("tell me a joke about {topic}")

# 添加路由   API接口详情
add_routes(
    app,
    prompt | llm,
    path="/joke",
)

if __name__ == "__main__":
    import uvicorn


    uvicorn.run(app, host="localhost", port=8001)